﻿using B.S.Ingredients.APIRead.Application.Command.ImmunityCommand;
using B.S.Ingredients.Domain;
using B.S.Ingredients.ErrorCode;
using B.S.Ingredients.Infartructrue.Interfaces;
using MediatR;

namespace B.S.Ingredients.APIRead.Application.CommandHandler.ImmunityCommandHandler
{
    public class ImmunitFtCommandHandler:IRequestHandler<ImmunitFtCommand,APIResult<List<Immunity>>>
    {
        public ImmunitFtCommandHandler(IBaseRepository<Immunity> immunitRepository)
        {
            ImmunitRepository = immunitRepository;
        }

        public IBaseRepository<Immunity> ImmunitRepository { get; }

        public async Task<APIResult<List<Immunity>>> Handle(ImmunitFtCommand request, CancellationToken cancellationToken)
        {
            var path = ImmunitRepository.GetAll().Where(a => a.Productuins == request.Productuins);
            if (path == null)
            {
                return new APIResult<List<Immunity>>
                {
                    Code = ResultCode.error,
                    Mag = "保健信息不存在",
                    Data = null
                };
            }
            else
            {
                return new APIResult<List<Immunity>>
                {
                    Code = ResultCode.success,
                    Mag = "反填成功",
                    Data = path.ToList()
                };

            }
        }
        
    }
}
